import os
import sys
from esp_toytrain_client.wifi_uploader import ESPObject

upload_type = sys.argv[1]
esp = ESPObject("192.168.1.7", 80)
os.chdir("../train_side")
if upload_type == "bootstrap":
    ret = input(
        "警告：上传bootstrap启动文件时，若出现网络不稳定等传输干扰情况，则可能对程序造成不可逆的破坏。\n"
        "一旦破坏发生，您将无法通过Wifi网络传输文件，仅能通过串口重新上传。确定要上传吗 (y/[N])"
    )
    if ret.lower() == "y":
        esp.upload_code(["main.py", "bootstrap"], False)
    else:
        print("上传已放弃")
elif upload_type == "libs":
    esp.upload_code(["third_parties"], False)
elif upload_type == "code":
    esp.upload_code(["esp_toytrain"], False)
    os.chdir("../controller_side")
    esp.upload_code(["shared_types"], False)
    # esp.upload_code(["fs_services.py"], False)
elif upload_type == "all":
    esp.upload_code(
        ["esp_toytrain", "shared_types", "third_parties", "main.py", "bootstrap"], False
    )
else:
    print("Invalid upload type", upload_type)
# esp.upload_code(["23.wav"], False)
# esp.upload_code(["libraries"], False)
